package com.myproject.music.controller;

import com.myproject.music.BizException;
import com.myproject.music.domain.Order;
import com.myproject.music.service.OrderService;

import com.myproject.music.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "专辑管理0515郭彦良")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("查询专辑列表")
    @ApiImplicitParam(name="name", value="专辑名", dataType="string", dataTypeClass=String.class)
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = "name", required = false) String orderName) {
        List<Order> list = orderService.selectOrderByParam(orderName);
        return AjaxResult.success(list);
    }

    @ApiOperation(value="获取专辑详细信息", notes = "根据专辑ID获取详细信息")
    @ApiImplicitParam(name = "id", value="专辑ID", required=true, dataType = "long", paramType="path", dataTypeClass=Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        Order order1=orderService.selectOrderById(id);
        if(order1 ==null||order1.getId()==null){
            throw new BizException(404,"专辑"+id+"不存在");
        }
        return AjaxResult.success(order1);
    }
    // @Log(title = "歌手管理",businessType = BusinessType.INSERT)

    @ApiOperation("新增专辑")

    @PostMapping("/insertorder")
    public AjaxResult add( @RequestBody Order order) {
        return AjaxResult.success(orderService.insertOrder(order));
    }

    @ApiOperation("修改专辑")
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return AjaxResult.success(orderService.updateOrder(order));
    }

    @ApiOperation("删除专辑")
    @ApiImplicitParam(name="id", value = "专辑ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return AjaxResult.success(orderService.deleteOrderById(id));
    }

    @ApiOperation("查询全部专辑列表")
    @GetMapping("/orderlist")
    public AjaxResult getAllOrderList() {
        return AjaxResult.success(orderService.selectOrderAll());
    }
}
